home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / yerk / mps231ss.hqx / Mops source / Nuc source / Setup.asm < prev    next >
Assembly Source File  |  1992-07-20  |  4KB  |  150 lines

  1. ; This file contains the code which initializes the system.
  2.  
  3.     jtbl    run
  4.     ref    main
  5.  
  6.     ipath    "::mops source:nuc source:"
  7.  
  8.     IF1
  9.     incl    "macrox.asm"
  10.     incl    "globals.psm"
  11.     ENDI
  12.  
  13. ;            ========================
  14.  
  15. sbase    equ    *+32766
  16.  
  17.     bra.s    run
  18.  
  19. maxDic    dc.l    300000    ; These correspond to the quantities in the
  20. minHeap    dc.l    20000    ;  main dictionary with the same names.
  21. dicSize    dc.l    0    ; We compute DicSize here, and the others
  22. StkSpace    dc.l    50000    ;  are set up by Install.  Just to be safe,
  23. RstkSpace    dc.l    6000    ; When Main starts, it copies them from here
  24.             ; to the main dic.
  25. installed    dc.b    0    ; Set NZ by Install if this is an installed
  26. spare    dc.b    0    ;  application
  27.  
  28. run    nop        ; Space for a debugger trap if necessary
  29.  
  30. ; NOTE: all the above quantities are at offsets from the start which are ASSUMED by
  31. ; Install.  Don't move anything without checking Install!!
  32.  
  33.     move.l    CurrentA5,a5    ; In case we're restarting after a crash
  34.     lea    sbase,a3    ; Make us addressable
  35.  
  36.     move.l    #$CDCD,-(a7)    ; Safety margin on return stack, with markers.
  37.     move.l    #$ABAB,-(a7)    ; These are easy to recognize in Macsbug,
  38.             ;  and the top one is odd in case we
  39.             ;  try to use it as a return address.
  40.     move.l    a7,d7    ; Leave R0 value in D7 for Main
  41.     move.l    a7,a0
  42.     sub.l    RstkSpace,a0
  43.     clr.l    -(a0)
  44.     clr.l    -(a0)
  45.     move.l    #$CD,-(a0)    ; Set up data stack:
  46.     move.l    #$AB,-(a0)    ; Safety margin on data stack, with markers
  47.     move.l    a0,a6
  48.     move.l    a0,d6    ; Leave S0 value in D6 for Main
  49.  
  50.     sub.l    StkSpace,A0    ; Reserve data stack space
  51.     move.l    a0,d4    ; Save addr for after _InitGraf etc.
  52.     exg    a6,a7    ; Setup for system calls
  53.     pea    -4(a5)
  54.     _InitGraf
  55.     move.l    d4,a0
  56.     _SetApplLimit
  57.     _MaxApplZone
  58.     _MaxMem        ; Leaves D0 = max available heap block size
  59.     move.l    d0,d3    ; Save in D3 for later
  60.     _InitFonts  
  61. ;    MOVE.L    #$0000FFFF,D0
  62. ;    _FlushEvents    ; (whichMask,stopMask:EventMask)
  63.             ; Hmmm.  Do we really need to flush
  64.             ;  events?  Typeahead could be
  65.             ;  useful.
  66.     _InitWindows  
  67.     _TeInit  
  68.     _InitMenus
  69.     _InitCursor
  70.  
  71. ; Now we check the availability of some traps:
  72.  
  73.     MOVE.W    #$9F,D0
  74.     _GetTrapAddressTool
  75.     move.l    a0,a4    ; A4 = unimplemented trap addr    
  76.     MOVEQ    #$60,D0    ; Get WaitNextEvent trap addr
  77.     _GetTrapAddressTool
  78.     cmp.l    a0,a4    ; If different from unimpl, WNE is available.
  79.     sne    d5
  80.     beq.s    .su1
  81.     moveq    #-1,d0    ; And if WNE is available, so is StripAddress
  82.     _StripAddress    ; Get StripAddress mask to D0
  83.     bra.s    .su2
  84. .su1    move.l    Lo3Bytes,d0    ; If no WNE, SA mask is Lo3Bytes
  85. .su2    move.l    d0,d4    ; Leave in D4 for Main
  86.  
  87.     lsl.l    #8,d5    ; Now we set various flags in D5 for Main
  88.     move.l    #$198,d0    ; HWpriv trap number
  89.     _GetTrapAddressOS
  90.     cmp.l    a0,a4    ; NE-> HWpriv is available
  91.     sne    d5
  92.     lsl.l    #8,d5
  93.     move.l    #$1AD,d0    ; Gestalt trap number
  94.     _GetTrapAddressOS
  95.     cmp.l    a0,a4    ; NE-> Gestalt is available
  96.     sne    d5
  97.     beq.s    .noGest
  98.     move.l    #'proc',d0    ; If so, we'll use it to get info
  99.     dc.w    $A1AD    ; _Gestalt
  100.     bne.s    .noGest
  101.     move.l    a0,-(a7)    ; Proc# to stack for Main
  102.     move.l    #'fpu ',d0
  103.     dc.w    $A1AD    ; _Gestalt
  104.     bne.s    .noFPU    ; If call failed, assume no FPU
  105.     move.l    a0,-(a7)    ; FPU status to stack for Main
  106.     beq.s    .su3
  107.     clr.l    -(a7)    ; If FPU present, initialize it as per
  108.     clr.l    -(a7)    ;  Tech Note 146.
  109.     dc.w    $F21F,$9800    ;    fmovem    (a7)+,FPCR/FPSR
  110.     bra.s    .su3
  111.  
  112. .noGest    moveq    #1,d0    ; No Gestalt, or call failed.
  113.     move.l    d0,-(a7)    ;  Assume processor is 68000.
  114. .noFPU    clr.l    -(a7)    ;  And no FPU
  115.  
  116. .su3    tst.b    installed-sbase(a3)
  117.     bne    callMain    ; If this is an installed application, skip
  118.             ;  the next bit
  119.  
  120. ; Now we set the size of the main (CODE 2) resource
  121.  
  122.     sub.l    MinHeap,d3    ; Subtract minimum heap requirement
  123.     move.l    MaxDic,d0    ; Is remaining heap bigger than max
  124.     cmp.l    d0,d3    ;  dic size needed?
  125.     blt.s    .1    ; No  - grab it all
  126.     move.l    d0,d3    ; Yes - only grab max size needed
  127. .1    move.l    d3,dicSize-sbase(a3)    ; Final dic size
  128.     clr.l    -(sp)
  129.     move.l    #'CODE',-(a7)
  130.     move.w    #2,-(a7)
  131.     _GetResource
  132.     move.l    (a7),a0    ; A0 = handle to CODE 2 (Main)
  133.     _Hunlock        ; Unlock it just in case, since we're
  134.     move.l    (a7),a0    ;  going to expand it
  135.     move.l    d3,d0
  136. ;    add.l    #nucTop-start,d0 ; Add nucleus size to dic requirement
  137.     _SetHandleSize    ; Set CODE 2 to total size
  138.     tst.l    d0    ; Did we get the memory?
  139.     beq.s    .2    ; Yes
  140.     move.w    #3,-(a7)
  141.     _SysBeep
  142.     _ExitToShell    ; No - something's terribly wrong - virus?
  143.  
  144. .2    move.l    (a7)+,a0    ; Lock CODE 2 to make sure it doesn't get
  145.     _Hlock        ;  purged since we've expanded it
  146. callMain
  147.     lea    maxDic,a2
  148.  
  149.     jmp    main
  150.